#ifndef _Movement_H_
#define	_Movement_H_

#include "math/vec2.h"
#include <vector>

namespace math
{

// handling movement around. 
// this class interally thinks the world is square 

class	Movement
{
public:

	enum SCREEN_MODE
	{
		SCREEN_MODE_UNSETYET,
		SCREEN_MODE_LANDSCAPE,
		SCREEN_MODE_PORTRAIT,
		SCREEN_MODE_SQUARE,
		SCREEN_MODE_COUNT,
	};

	struct Force
	{
		bool		m_IsFinish;
		math::Vec2	m_Dir;
		float		m_Duration;
		float		m_Acceleration;		

		Force() :	m_IsFinish(false),
					m_Duration(0),
					m_Acceleration(0)
		{			

		}

		void	Reset()
		{
			m_IsFinish = false;
			m_Dir = math::Vec2(0,0);			
			m_Duration = 0;
			m_Acceleration = 0;
		}
	};

							Movement(float	MoveSpeed = 1.0f, const math::Vec2& InitialPos = math::Vec2(0.5f,0.5f));
							~Movement();
	void					Tick(float dt);
	void					SetCurrent(const math::Vec2& Pos);
	void					SetTarget(const math::Vec2& ScreenPos, bool StopAtTarget = false);
	const math::Vec2&		GetTarget() { return m_TargetPos; };
	void					SetTarget(float Degree);

	const math::Vec2& 		GetPos() const { return m_CurrentPos; };
	const math::Vec2&		GetPreviousPos() const { return m_PreviousPos; };
	float					GetSpeed() const { return m_MoveSpeed; };
	void					SetMoveSpeed(float f) { m_MoveSpeed = f; };
	void					Stop() { m_IsMoving = false; };
	
	//math::Vec2			GetForward() const ;
	//math::Vec2			GetRight() const ;
	//math::Vec2			GetForwardW2H() const;	// for rendering to screen; compensates for width/height ratios
	//float					GetRemainder() const;
	void					SetSnap(bool b) { m_EnableSnap = b; };
	bool					GetSnap() const { return m_EnableSnap; };

	// implement this also
	//void					SetBoundary(const math::Vec2& Min, const math::Vec2& Max){}

	math::Vec2				VectorFromAngle(float Angle);
	void					SetMinMax(const math::Vec2& Min,const math::Vec2& Max );

	void					AddForce(const math::Vec2& Dir, float Duration, float Acceleration);
	void					ClearForces();	
	bool					GetIsUnderForce() const { return (int)m_Forces.size() > 0;  };
	static void 			ChangeToSquareVec2(math::Vec2& P);
	static void 			ChangeToScreenPos(math::Vec2& P);

private:

	
	void					TickForces(float dt);

	math::Vec2				m_PreviousPos;
	math::Vec2				m_CurrentPos;
	math::Vec2				m_TargetPos;

	math::Vec2				m_SquarePos;
	math::Vec2				m_SquareTarget;
	math::Vec2				m_SquareDir;

	float					m_MoveSpeed;
	bool					m_EnableSnap;
	math::Vec2				m_Dir;
	bool					m_IsMoving;
	bool					m_StopAtTarget;
	
	static SCREEN_MODE		m_ScreenMode;
	bool					m_IsRestrianed;
	math::Vec2				m_Min;
	math::Vec2				m_Max;
	math::Vec2				m_ForceMovement;

	std::vector<Movement::Force*>			m_Forces;
	
};


}
#endif //_Movement_H_